package com.tanhua.server.controller;

import com.tanhua.server.service.SoundService;
import com.tanhua.server.vo.PeachBlossomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("peachblossom")
public class PeachBlossomController {
    @Autowired
    private SoundService soundService;
    @PostMapping
    public ResponseEntity<Void> sendSound(@RequestParam("soundFile") MultipartFile soundFile){
        try {
            Boolean bool = this.soundService.sendSound(soundFile);
            if (bool) {
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    @GetMapping
    public ResponseEntity<PeachBlossomVo> getSound(){
        try {
            PeachBlossomVo PeachBlossomVo = this.soundService.getSound();
            if (PeachBlossomVo != null) {
                return ResponseEntity.ok(PeachBlossomVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

}
